package MediaOnline.VideoPlayer;

import java.util.ArrayList;
import java.util.List;

import MediaOnline.GUI.R;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VideoGalleryAdapter extends BaseAdapter {
	private Context context;
	private List<VideoViewInfo> videoItems;

	LayoutInflater inflater;

	public VideoGalleryAdapter(Context _context, ArrayList<VideoViewInfo> _items) {
		context = _context;
		videoItems = _items;

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	public int getCount() {
		// TODO Auto-generated method stub
		return videoItems.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return videoItems.get(position);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup) Day la phuong thuc tra ve doi tuong view cho moi
	 * dong dai dien o day la ListView
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View videoRows = inflater.inflate(R.layout.list_items, null);
		ImageView videoThumb = (ImageView) videoRows
				.findViewById(R.id.ImageView);
		if (videoItems.get(position).thumbPath != null) {
			videoThumb
					.setImageURI(Uri.parse(videoItems.get(position).thumbPath));

		}
		TextView videoTitle = (TextView) videoRows.findViewById(R.id.TextView);
		videoTitle.setText(videoItems.get(position).title);
		return videoRows;
	}

}
